$().ready(function() {
    $(".datepicker").datepicker({ format: "yyyy-mm-dd", language: "cn" });

    // $('.btn-js').button("toggle");
    $('select').each(function(){
        var v = $(this).data('value')
        if(typeof(v)!="undefined"){ 
            $(this).val(v);
        }
    });
});




function HjAlert(status) {
    if (status == 'error') {
        $("#alertViewError").show();
        setTimeout(function() {
            $("#alertViewError").hide();
        }, 2200);
    } else {

        $("#alertViewSuccess").show();
        $('#alertViewSuccess .cover').animate({ left: 90 }, 1000);
        setTimeout(function() {
            $("#alertViewSuccess").hide();
            $('#alertViewSuccess .cover').css({ left: 20 });
        }, 1300);
    }

}


function CommPostProduct(url, post) {
    var n = noty({
        text: '<i class="fa-spin fa fa-spinner" aria-hidden="true"></i>  &nbsp; &nbsp;Loading...',
        type: 'notification',
        dismissQueue: true,
        layout: 'center',
        theme: 'defaultTheme',
        timeout: 15000,
        animation: {
            open: { height: 'toggle' }, // or Animate.css class names like: 'animated bounceInLeft'
            close: { height: 'toggle' }, // or Animate.css class names like: 'animated bounceOutLeft'
            easing: 'swing',
            speed: 0 // opening & closing animation speed
        },
    });
    // console.log( encodeURIComponent(JSON.stringify(post)));
    setTimeout(function() {
        $.ajax({
            type: "POST",
            url: url,
            headers: {},
            data: "postjson=" + encodeURIComponent(JSON.stringify(post)),
            dataType: "html", // html/json/jsonp/xml
            success: function(msg) {
                if (msg > 0) {
                    HjAlert();
                    n.close();
                } else {
                    HjAlert('error');
                    n.close();
                }
            },
            error: function() {
                HjAlert('error');
                n.close();
            }
        });
    }, 500);

}


function Toast(message) {
    var n = noty({
        text: message,
        type: 'notification',
        dismissQueue: true,
        layout: 'center',
        theme: 'defaultTheme',
        timeout: 15000,
        animation: {
            open: {
                height: 'toggle'
            }, // or Animate.css class names like: 'animated bounceInLeft'
            close: {
                height: 'toggle'
            }, // or Animate.css class names like: 'animated bounceOutLeft'
            easing: 'swing',
            speed: 0 // opening & closing animation speed
        },
    });
}
